﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TrackIT.Common;

namespace TrackIT.UnitTest.Entities
{
    [TestClass]
    public class TaskTest
    {
        [TestMethod]
        public void Ctor_Default_TaskNameSet()
        {
            Task target = new Task();
            Assert.AreEqual("", target.Name);
            Assert.AreEqual("", target.Description);
        }

        [TestMethod]
        public void Ctor_Name_TaskNameSet()
        {
            Task target = new Task("TaskName");
            Assert.AreEqual("TaskName", target.Name);
            Assert.AreEqual("", target.Description);
        }

        [TestMethod]
        public void Ctor_NameDescription_TaskNameSet()
        {
            Task target = new Task("TaskName", "Description");
            Assert.AreEqual("TaskName", target.Name);
            Assert.AreEqual("Description", target.Description);
        }
        
        [TestMethod]
        public void Ctor_NameDescriptionRecuringTime_TaskNameSet()
        {
            Task target = new Task("Task|Description|09:30");
            Assert.AreEqual("Task", target.Name);
            Assert.AreEqual("Description", target.Description);
            Assert.AreEqual(new DateTime(1, 1, 1, 9, 30, 0), target.RecuringTime);
        }

        [TestMethod]
        public void Ctor_InvalidRecuringTime_NoException()
        {
            Task target = new Task("Task|Description|49:30");
            Assert.AreEqual("Task", target.Name);
            Assert.AreEqual("Description", target.Description);
            Assert.AreEqual(new DateTime(1, 1, 1, 0, 0, 0), target.RecuringTime);
        }

        [TestMethod]
        public void RecuringTime_ChangeRecuringTime_RecuringTimeChanged()
        {
            Task target = new Task("Task|Description|09:30");
            target.RecuringTime = new DateTime(1, 1, 1, 12, 15, 0);
            Assert.AreEqual(new DateTime(1, 1, 1, 12, 15, 0), target.RecuringTime);
        }

        [TestMethod]
        public void Equals_AreEqual_True()
        {
            Task target1 = new Task("Task", "Description");
            Task target2 = new Task("Task", "Description");

            Assert.IsTrue(target1.Equals(target2));
        }

        [TestMethod]
        public void Equals_AreNotEqual_False()
        {
            Task target1 = new Task("Task", "Description");
            Task target2 = new Task("Task2", "Description");

            Assert.IsFalse(target1.Equals(target2));
        }

        [TestMethod]
        public void Equals_CompareWithNull_False()
        {
            Task target = new Task("Task", "Description");

            Assert.IsFalse(target.Equals(null));
        }


        [TestMethod]
        public void GetHashCode_AreEqual_True()
        {
            Task target1 = new Task("Task", "Description");
            Task target2 = new Task("Task", "Description");
            int actual1 = target1.GetHashCode();
            int actual2 = target2.GetHashCode();

            Assert.AreEqual(actual1, actual2);
        }
    }
}
